/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import java.util.concurrent.TimeUnit;

/**
 * <p>Project: jse2204 - T9
 * <p>Powered by webrx On 2022-09-30 16:45:54
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class T9 {

    //volatile List<String> list = new ArrayList<>();

    Vector<String> list = new Vector<>();

    void add(){
        String t = Thread.currentThread().getName();
        System.out.printf("%s线程启动..%n",t);
        while(true){
            try{
                TimeUnit.SECONDS.sleep(1);
            }catch(Exception e){
                e.printStackTrace();
            }
            String item = "item:"+list.size();
            list.add(item);
            System.out.println(item);
        }
    }

    void check(){
        String t = Thread.currentThread().getName();
        System.out.printf("%s线程启动..%n",t);
        while(list.size()<5){

        }
        System.out.printf("%s:到5个元素了",t);
    }

    public static void main(String[] args) {
        T9 t = new T9();

        var a = new Thread(t::add,"工作");
        a.start();

        var b = new Thread(t::check,"统计");
        b.start();


    }
}
